﻿using Binding;
using MemoryPack;
using Net.Event;
using Net.Serialize;
using Net.System;
using SerializeTesting;
using System.Diagnostics;

class Program
{
    unsafe static void Main()
    {
        NDebug.BindConsoleLog();
        if (!Directory.Exists(@"..\..\..\Binding\"))
        {
            Directory.CreateDirectory(@"..\..\..\Binding\");
            Fast2BuildMethod.BuildAll(@"..\..\..\Binding\", SerializeMode.MemoryCopy, 1, typeof(Test)); //生成绑定类型文件
            return;
        }

        var test = new Test()
        {
            f1 = 123,
            f2 = 123,
            f3 = true,
            f4 = 125,//4567,
            f5 = 6842,
            f6 = 'k',
            f7 = 4567891,
            f8 = 456478971,
            f9 = 1234.4564f,
            f10 = 47489745665,
            f11 = 4564654123123,
            f12 = 123.456456,
            f13 = DateTime.Now,
            f14 = 456123.45676465m,
            f15 = "John-你好啊",

            //xf1 = 123,
            //xf2 = 123,
            //xf3 = true,
            //xf4 = 4567,
            //xf5 = 6842,
            //xf6 = 'k',
            //xf7 = 4567891,
            //xf8 = 456478971,
            //xf9 = 1234.4564f,
            //xf10 = 47489745665,
            //xf11 = 4564654123123,
            //xf12 = 123.456456,
            //xf13 = DateTime.Now,
            //xf14 = 456123.45676465m,
            //xf15 = "Johnxxxxxxxxxzzzwwq",

            //fa1 = new byte[] { 1, 2, 3 },
            //fa10 = new long[] { 1, 2, 3 },
            //fa15 = new string[] { "John", "John", "John", },

            //fl1 = new List<byte> { 1, 2, 3 },
            //fl10 = new List<long> { 1, 2, 3 },
            //fl15 = new List<string> { "John", "John", "John", },

            //fl1 = new List<byte> { 1, 2, 4 },
            /*fd1 = new Dictionary<int, byte> { { 1, 5 }, { 2, 3 }, { 5, 8 } },

            test = new Test()
            {
                f1 = 123,
                f2 = 123,
                f3 = true,
                f4 = 4567,
                f5 = 6842,
                f6 = 'k',
                f7 = 4567891,
                f8 = 456478971,
                f9 = 1234.4564f,
                f10 = 47489745665,
                f11 = 4564654123123,
                f12 = 123.456456,
                f13 = DateTime.Now,
                f14 = 456123.45676465m,
                f15 = "John",
            },
            testArray = new Test[]
            {
                new Test()
                {
                    f1 = 123,
                    f2 = 123,
                    f3 = true,
                    f4 = 4567,
                    f5 = 6842,
                    f6 = 'k',
                    f7 = 4567891,
                    f8 = 456478971,
                    f9 = 1234.4564f,
                    f10 = 47489745665,
                    f11 = 4564654123123,
                    f12 = 123.456456,
                    f13 = DateTime.Now,
                    f14 = 456123.45676465m,
                    f15 = "John",
                },
                new Test()
                {
                    f1 = 123,
                    f2 = 123,
                    f3 = true,
                    f4 = 4567,
                    f5 = 6842,
                    f6 = 'k',
                    f7 = 4567891,
                    f8 = 456478971,
                    f9 = 1234.4564f,
                    f10 = 47489745665,
                    f11 = 4564654123123,
                    f12 = 123.456456,
                    f13 = DateTime.Now,
                    f14 = 456123.45676465m,
                    f15 = "John",
                }
            },
            testList = new List<Test>()
            {
                new Test()
                {
                    f1 = 123,
                    f2 = 123,
                    f3 = true,
                    f4 = 4567,
                    f5 = 6842,
                    f6 = 'k',
                    f7 = 4567891,
                    f8 = 456478971,
                    f9 = 1234.4564f,
                    f10 = 47489745665,
                    f11 = 4564654123123,
                    f12 = 123.456456,
                    f13 = DateTime.Now,
                    f14 = 456123.45676465m,
                    f15 = "John",
                },
                new Test()
                {
                    f1 = 123,
                    f2 = 123,
                    f3 = true,
                    f4 = 4567,
                    f5 = 6842,
                    f6 = 'k',
                    f7 = 4567891,
                    f8 = 456478971,
                    f9 = 1234.4564f,
                    f10 = 47489745665,
                    f11 = 4564654123123,
                    f12 = 123.456456,
                    f13 = DateTime.Now,
                    f14 = 456123.45676465m,
                    f15 = "John",
                }
            },*/

            testArray = new Test[] { null, null, new Test(), null },
            testList = new List<Test>() { null, null, null, new Test(), null, null }
        };

        Task.Run(() =>
        {
            while (true)
            {
                var stopwatch = Stopwatch.StartNew();
                for (int i = 0; i < 10000000; i++)
                {
                    var bin = MemoryPackSerializer.Serialize(test);
                    var val = MemoryPackSerializer.Deserialize<Test>(bin);
                }
                stopwatch.Stop();
                Console.WriteLine("MemoryPack 1000万次:" + stopwatch.Elapsed);
            }
        });

        Task.Run(() =>
        {
            BufferPool.Size = 1024 * 1024;
            BufferPool.SegmentType = SegmentType.Segment;
            while (true)
            {
                var stopwatch = Stopwatch.StartNew();
                for (int i = 0; i < 10000000; i++)
                {
                    var bin = NetConvertFast2.SerializeObject(test);
                    var val = NetConvertFast2.DeserializeObject<Test>(bin);
                }
                stopwatch.Stop();
                Console.WriteLine("BinaryMemoryCopy 1000万次:" + stopwatch.Elapsed);
            }
        });

        Task.Run(() =>
        {
            BufferPool.SegmentType = SegmentType.Segment;
            while (true)
            {
                var stopwatch = Stopwatch.StartNew();
                for (int i = 0; i < 10000000; i++)
                {
                    var bin = NetConvertBinary.SerializeObject(test);
                    var val = NetConvertBinary.DeserializeObject<Test>(bin);
                }
                stopwatch.Stop();
                Console.WriteLine("BinarySerialize 1000万次:" + stopwatch.Elapsed);
            }
        });
        Console.ReadLine();
    }
}